/*
*  Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
*/
package com.pitop.order.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.OrderDetailException;
import com.pitop.order.api.OrderDetailFeignApi;
import com.pitop.order.entity.OrderDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 订单详情
 *
 * @author berton
 */
@Service("orderDetailSVImpl")
@Slf4j
public class OrderDetailSVImpl {

    @Autowired
    private OrderDetailFeignApi orderDetailFeignApi;

    /**
     * 加载一个对象OrderDetail
     *
     * @param id
     * @return OrderDetail
     */
    public OrderDetail load(Long id) {
        if (id == null) {
            throw new OrderDetailException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return orderDetailFeignApi.load(id);
    }

    /**
     * 加载一个对象OrderDetail 通过id
     *
     * @param id
     * @return OrderDetail
     */
    public OrderDetail loadById(Long id) {
        if (id == null) {
            throw new OrderDetailException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return orderDetailFeignApi.loadById(id);
    }


    /**
     * 删除对象OrderDetail
     *
     * @param id
     */

    public void delete(Long id) {
        if (id == null) {
            throw new OrderDetailException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        orderDetailFeignApi.delete(id);
    }


    /**
     * 查询OrderDetail分页
     *
     * @param orderDetail 对象
     * @param curPage     当前页
     * @param pageSize    分页条数
     * @return List<OrderDetail>
     */
    public List<OrderDetail> list(OrderDetail orderDetail, int curPage, int pageSize) {
        return orderDetailFeignApi.list(orderDetail, curPage, pageSize);
    }

    /**
     * 查询OrderDetail分页
     *
     * @param id
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<OrderDetail>
     */
    public List<OrderDetail> list(Long id, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        OrderDetail orderDetail = new OrderDetail();
        orderDetail.setId(id);

        return orderDetailFeignApi.list(orderDetail, curPage, pageSize);
    }

    /**
     * 查询OrderDetail分页
     *
     * @param orderCode
     * @param curPage   当前页
     * @param pageSize  分页条数
     * @return List<OrderDetail>
     */
    public List<OrderDetail> listBox(String orderCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        return orderDetailFeignApi.listBox(orderCode, curPage, pageSize);
    }


    public int count(Long id) {
        return orderDetailFeignApi.count(id);
    }


    public int count(OrderDetail orderDetail) {
        return orderDetailFeignApi.count(orderDetail);
    }


    /**
     * 保存
     *
     * @param orderDetail 实体
     * @throws BaseException
     */
    public void save(OrderDetail orderDetail) {
        if (orderDetail == null) {
            throw new OrderDetailException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        orderDetailFeignApi.build(orderDetail);
    }

    /**
     * 更新
     *
     * @param orderDetail 实体
     * @throws BaseException
     */
    public void modify(OrderDetail orderDetail) {
        if (orderDetail == null) {
            throw new OrderDetailException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        orderDetailFeignApi.modify(orderDetail);
    }

}
